本文整理汇总了C#中System.Web.HttpResponse.RedirectPermanent方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.RedirectPermanent方法的具体用法?C# HttpResponse.RedirectPermanent怎么用?C# HttpResponse.RedirectPermanent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.RedirectPermanent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteResponse
/// <summary>
/// 写入到http回应
/// </summary>
/// <param name="response"></param>
public void WriteResponse(HttpResponse response) {
if (Permanent) {
response.RedirectPermanent(Url);
} else {
response.Redirect(Url);
}
}
示例2: Redirect
private static void Redirect(HttpResponse response, string url, bool permanent)
{
if (permanent) {
response.RedirectPermanent(url, true);
}
else {
response.Redirect(url, false);
}
}
示例3: CheckForTabExternalForwardOrRedirect
//.........这里部分代码省略.........
out permanentRedirect,
parentTraceId);
}
//check to make sure there isn't a blank redirect Url
if (redirectUrl == null)
{
//problem : no redirect Url to redirect to
//solution : cancel the redirect
string message = "Permanent Redirect chosen for Tab " +
tab.TabPath.Replace("//", "/") +
" but forwarding Url was not valid";
RedirectController.CancelRedirect(ref result, context, settings, message);
}
else
{
//if there was a redirect Url, set the redirect action and set the type of redirect going to use
doRedirect = true;
if (permanentRedirect)
{
result.Action = ActionType.Redirect301;
result.Reason = RedirectReason.Tab_Permanent_Redirect;
//should be already set, anyway
result.RewritePath = cleanPath;
}
else
{
//not a permanent redirect, check if the page forwarding is set
if (settings.ForwardExternalUrlsType == DNNPageForwardType.Redirect301)
{
result.Action = ActionType.Redirect301;
result.Reason = RedirectReason.Tab_External_Url;
}
else if (settings.ForwardExternalUrlsType == DNNPageForwardType.Redirect302)
{
result.Action = ActionType.Redirect302;
result.Reason = RedirectReason.Tab_External_Url;
}
}
}
break;
default:
//only concern here is if permanent redirect is requested, but there is no external url specified
if (result.Reason == RedirectReason.Tab_Permanent_Redirect)
{
bool permRedirect = tab.PermanentRedirect;
if (permRedirect)
{
//problem : permanent redirect marked, but no forwarding url supplied
//solution : cancel redirect
string message = "Permanent Redirect chosen for Tab " +
tab.TabPath.Replace("//", "/") +
" but no forwarding Url Supplied";
RedirectController.CancelRedirect(ref result, context, settings, message);
}
}
break;
}
//do the redirect we have specified
if (doRedirect &&
(result.Action == ActionType.Redirect301 || result.Action == ActionType.Redirect302))
{
result.FinalUrl = redirectUrl;
if (result.Action == ActionType.Redirect301)
{
if (response != null)
{
//perform a 301 redirect to the external url of the tab
response.AppendHeader("X-Redirect-Reason",
result.Reason.ToString().Replace("_", " ") + " Requested");
response.RedirectPermanent(result.FinalUrl);
}
}
else
{
if (result.Action == ActionType.Redirect302)
{
if (response != null)
{
//perform a 301 redirect to the external url of the tab
response.AppendHeader("X-Redirect-Reason",
result.Reason.ToString().Replace("_", " ") + " Requested");
response.Redirect(result.FinalUrl);
}
}
}
finished = true;
}
}
}
}
}
catch (ThreadAbortException)
{
//do nothing, a threadAbortException will have occured from using a server.transfer or response.redirect within the code block. This is the highest
//level try/catch block, so we handle it here.
}
return finished;
}
示例4: ProcessRequestInner
//.........这里部分代码省略.........
}
// Get content
byte[] page;
lock (WebCache) {
// Read cache
page = WebCache[path] as byte[];
// If cache miss..
if (null == page) {
// Open WAR file
if (null == HttpRoot) {
try {
HttpRoot = ZipFile.Read(HttpRootFile.FullName);
} catch (Exception ex) {
// Log the exception
LogException(ex, "Variant-HttpRoot", Ids.System);
// Warn users that we're updating
response.Write("We're currently updating our content. Hang tight - the site will be back shortly!");
return;
}
if (null == HttpRoot["/index.html"]) {
throw new Exception("Missing '/index.html' in WAR");
}
}
// Open file
ZipEntry file;
if (null == (file = HttpRoot[path])) {
// File not found - redirect to virtual space
response.CacheControl = "public";
response.Expires = 31536000;
response.ExpiresAbsolute = DateTime.Now.AddYears(1);
response.Cache.SetCacheability(HttpCacheability.Public);
response.RedirectPermanent("/#!" + path, true);
return;
}
// Extract
using (var stream = new MemoryStream()) {
file.Extract(stream);
page = stream.ReadAllToByteArray();
}
// Add to cache
WebCache[path] = page;
}
}
// Set cache headers
if (path.Contains(".nocache.")) {
response.CacheControl = "private";
response.Expires = 0;
response.ExpiresAbsolute = DateTime.Now;
response.Cache.SetCacheability(HttpCacheability.NoCache);
} else if (path.Contains(".cache.")) {
response.CacheControl = "public";
response.Expires = 365 * 24 * 60 * 60;
response.ExpiresAbsolute = DateTime.Now.AddDays(365);
response.Cache.SetCacheability(HttpCacheability.Public);
} else {
response.CacheControl = "private";
response.Expires = 1 * 24 * 60 * 60;
response.ExpiresAbsolute = DateTime.Now.AddDays(1);
response.Cache.SetCacheability(HttpCacheability.Private);
}
// Set content type
switch (Path.GetExtension(path).ToUpperInvariant()) {
case ".JS":
response.ContentType = "text/javascript";
break;
case ".JSON":
response.ContentType = "application/json";
break;
case ".CSS":
response.ContentType = "text/css";
break;
case ".JPG":
case ".JPEG":
response.ContentType = "image/jpeg";
break;
case ".PNG":
response.ContentType = "image/png";
break;
case ".GIF":
response.ContentType = "image/gif";
break;
}
// Set compression
response.Compress(request);
// Write
response.OutputStream.Write(page, 0, page.Length);
}