我将我的站点升级为使用传统ASP.Net webforms中的ASP.Net MVC.我正在使用MVC路由将旧.aspx页面的请求重定向到它们的新Controller/Action等效项:
routes.MapRoute(
"OldPage",
"oldpage.aspx",
new { controller = "NewController", action = "NewAction", id = "" }
);
Run Code Online (Sandbox Code Playgroud)
这对于页面非常有用,因为它们直接映射到控制器和操作.但是,我的问题是图像请求 - 我不知道如何重定向这些传入的请求.
我需要将http://www.domain.com/graphics/image.png的传入请求重定向到http://www.domain.com/content/images/image.png.
使用该.MapRoute()方法时的正确语法是什么?
在托管的IIS7环境中,我正在寻找使用无扩展名文件名的最简单方法.我只有以下页面:
index.html(或.aspx) - > domain.com gallery.html - > domain.com/gallery videos.html - > domain.com/videos等...
我只有一些页面,我没有动态代码,没什么特别的.我开发我发现所有的例子或我在其他网站使用方法围绕动态内容,网页等,我只是在寻找最简单的解决方案,非常不需要安装任何形式的URL重写模块.最好是,我可以保留.html扩展名,而不是将站点转换为ASP.NET项目,但这是一个选项.
谢谢.
所以我知道这看起来有点奇怪,但为了保持一致性,我希望我的所有网址都以这种形式出现:http://domain.com/page/到目前为止,我已经让常规页面正常工作,但我不能似乎让错误页面正常工作.
如果用户访问不存在的页面或目录,我希望浏览器硬重定向到:http://domain.com/404/但是,此目录实际上不存在.错误页面的真实位置将在/pages/errors/404.php下
此外,虽然我不需要所有各种错误(400,401,403,404,500)的确切答案,但我将应用任何方法将所有这些重定向到他们的"正确"URL(例如http) ://domain.com/400/ http://domain.com/500/等)
有任何想法吗?
如何在ASP.NET中重写URL?
我希望用户能够转到http://www.website.com/users/smith而不是http://www.website.com/?user=smith
我在纯WCF上下文中运行了一些RESTful服务(即没有启用ASP.NET兼容性,因此没有HttpContext.Current可用的对象).
服务的URL在请求开始时使用IHttpModule(在此时确实具有HttpContext并使用其重写HttpContext.Current.RewritePath)来重写,以.svc从URL中删除诸如扩展之类的内容.
但是,我需要访问WCF基础结构中请求的原始URL.是否有一个相当于HttpContext.Current.Request.RawUrl上OperationContext或WebOperationContext类哪儿了吗?使用WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri返回重写的URL而不是原始的URL.
wcf url-rewriting httpcontext operationcontext weboperationcontext
我在URL Rewrite中得到了这个角色.用__CODE__to 重写每个请求到网站__CODE__
<rule name="Force HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
我需要在此角色中使用其他角色或异常来重写或将特定URL重定向到HTTP.
那可能吗?谢谢.
我使用这里给出的答案作为尝试向我的web.config文件添加重写规则的基础.我希望它匹配任何未在localhost上运行的url以强制https.
这就是我现在所拥有的:
<system.webServer>
<rewrite> <!-- force https - https://stackoverflow.com/a/15119044/51 -->
<rules>
<rule name="Redirect HTTP to HTTPS" stopProcessing="true">
<match url="^((?!localhost).)*$"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
</rule>
</rules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
我试图使用负面的环视,以便只匹配url中不包含"localhost"的url.但这不起作用.
那么如何设置此规则才能只重写非localhost网址呢?
在我的.htaccess文件中使用这个RewriteRule我得到RewriteRule:Bad flag delimiters,它在浏览器中返回500错误.任何人都可以指出我正确的方向.谢谢.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^dev/(.*)$ http://dev.example.com/$1 [L,R=301, NC]
Run Code Online (Sandbox Code Playgroud)
这是在数字海洋Droplet上的Ubuntu上.
main.go
package main
import (
"net/http"
)
func main() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.ListenAndServe(":8080", nil)
}
Run Code Online (Sandbox Code Playgroud)
目录结构:
%GOPATH%/src/project_name/main.go
%GOPATH%/src/project_name/static/..files and folders ..
Run Code Online (Sandbox Code Playgroud)
即使在阅读完文档后,我也无法理解http.StripPrefix这里究竟是做什么的.
1)localhost:8080/static如果删除,为什么我无法访问http.StripPrefix?
2)/static如果删除该功能,哪个URL映射到文件夹?
url-rewriting ×10
asp.net ×4
asp.net-mvc ×2
rewrite ×2
url-routing ×2
web-config ×2
.htaccess ×1
apache ×1
c# ×1
go ×1
html ×1
http ×1
httpcontext ×1
iis ×1
iis-7 ×1
java ×1
mod-rewrite ×1
redirect ×1
regex ×1
routing ×1
server ×1
ubuntu ×1
url ×1
wcf ×1