Allow POST to "static" files on ASP.net development server
I have an issue where a service needs to POST to the root of my ASP.net application that is running in my Visual Studio development instance (/myapp/ for example). However, ASP.net complains that "The HTTP verb POST used to access path '/myapp/' is not allowed.
How can I enable post to this path? Would URL rewriting be better (rewirte /myapp/ to /myapp/Default.aspx)?
Thanks.
EDIT:
I was just able to provide a work around by adding this to my Global.asax:
void Application_BeginRequest(object sender, EventArgs e) {
string p = Request.Path;
if (p.Equals("/myapp/")) {
var query = "?" + Request.QueryString.ToString();
if (query.Equals("?")) {
query = "";
}
Context.RewritePath("/myapp/Default.aspx" + query);
}
}
B开发者_如何学Gout I haven't tested this much and I am curious if there is a better solution. This also won't work when deployed to IIS.
You can use the Url Rewrite module for IIS to rewrite the path.
The rule would look something like this (haven't tested it):
<rewrite>
<rules>
<rule name="Rewrite to Default.aspx">
<match url="^myapp/+" />
<action type="Rewrite" url="/myapp/Default.aspx" appendQueryString="true" />
</rule>
</rules>
</rewrite>
This works for now. It's a hard coded rewrite in the Global.asax file:
void Application_BeginRequest(object sender, EventArgs e) {
string p = Request.Path;
if (p.Equals("/myapp/")) {
var query = "?" + Request.QueryString.ToString();
if (query.Equals("?")) {
query = "";
}
Context.RewritePath("/myapp/Default.aspx" + query);
}
}
I would love to see a better solution.
精彩评论