开发者

Allow POST to "static" files on ASP.net development server

开发者 https://www.devze.com 2023-02-19 21:48 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号