Tuesday, 15 July 2014

asp.net mvc 3 - MVC3 route by requested filename -


I have a flash based component that insists on asking for the XML settings file in an existing "directory".

This means that he is asking like paths ... /Home/mysettings.xml/Home/Record/mysettings.xml/AnotherController / AnotherAction / Mysettings.xml

It's upsetting I'm trying to create a MVC path to catch anything with mysettings.xml and make them take a steady action I am sending a view for XML and it is possible that I have to swap variies on the fly (possibly using URL queries).

This is the first time in my Global.asax.cs :

  routes. MapRoute ("XmlOverride", "mysettings.xml", new {controller = "home", action = "MyXML"});   

But I'm missing something that's either 404 or is going to the right place, no matter what I do for it. Is there any way that I take it on the path of right action? Can I preserve url wars in this process?

Thank you!

Update

I have a hacked version that works like this. I'm not sure that this is the best way to go, but it seems to work, does anyone have a better solution?

  routes MapRoute ("XmlOverride", "{c} /mysettings.xml", new {controller = "home", action = "myxl"}); Routes.MapRoute ("XmlOverride + Action", "{c} / {a} /mysettings.xml", new {controller = "home", action = "myxl"});   

You can not use {controller} or {action} because it is on a certain path.

You can rewrite the URL on the basis of your.

  & lt; Rewrite & gt; & Lt; Rules & gt; & Lt; Rule name = "MySettingsRewrite" & gt; & Lt; Mail url = "(\ w +) mysettings \ .xml $" /> & Lt; Action type = "rewrite" url = "/ home / my xml" /> & Lt; / Rules & gt; & Lt; / Rules & gt; & Lt; / Rewrite & gt;   

You will be re-examined for regex to ensure that I have got this right.

I can imagine that only one option is to implement its own root handler and use it.

No comments:

Post a Comment