سؤال

أرغب في تنفيذ إطار إعادة توجيه في C# من الوحدة المدارة الخاصة بي لـ IIS 7.
عندما أتصل context.Response.Redirect(@"http://www.myRedirect.org");يتم عرض الصفحة الصحيحة ولكن يتم عرض العنوان أيضًا في المتصفح. وهذا بالضبط ما لا أريده.
لذلك أريد شيئًا مثل:

private void OnBeginRequest(object sender, EventArgs e)
{
    HttpApplication app = (HttpApplication)sender;
    HttpContext context = app.Context;

    // make a frame redirect if a specified page is called
    if (context.Request.ServerVariable["HTTP_REFERER"].Equals(@"http://www.myPage.org/1.html"))
    {
        // perform the frame redirect here, but how?
        // so something like
        context.Response.Redirect(@"http://www.myRedirect.org");
        // but as I said that doesn't redirect as I want it to be
    }
}

أي أفكار حول ذلك؟
تعديل:جربت المثال ، لذلك لدي:

private void OnBeginRequest(object sender, EventArgs e)
{
    HttpApplication app = (HttpApplication)sender;
    HttpContext context = app.Context;

    // make a frame redirect if a specified page is called
    if (context.Request.ServerVariable["HTTP_REFERER"].Equals(@"http://www.myPage.org/1.html"))
    {
        // perform the frame redirect here, but how?
        context.Response.Write(@"<html>");
        context.Response.Write(@"<head>");
        context.Response.Write(@"</head>");
        context.Response.Write(@"<frameset rows=""100%,*"" framespacing=""0"" frameborder=""NO"" border=""0"">");
        context.Response.Write(@"<frame src=""http://www.myRedirect.org"" scrolling=""auto"">");
        context.Response.Write(@"</frameset>");
        context.Response.Write(@"<noframes>");
        context.Response.Write(@"<body>Some text...");
        context.Response.Write(@"</body>");
        context.Response.Write(@"</noframes>");
        context.Response.Write(@"</html>");
    }
}

ولكن هذا أيضا لا إعادة توجيه بشكل صحيح. لا يزال لدي عنوان إعادة التوجيه معروض في متصفحي. إذن أي فكرة أخرى؟

تحرير: من الواضح أنني ارتكبت خطأ. الرمز أعلاه يعمل ويفعل ما أريد. لم ينجح الأمر أولاً لأن عنوان URL الخاص بي كان يفعل شيئًا غير متوقع.

هل كانت مفيدة؟

المحلول

لأداء إعادة توجيه الإطار تحتاج إلى إعادة إرسال رمز HTML الذي يحتوي على إطار مع إطار واحد ، مع تعيين مصدره http://www.myredirect.org. فيما يتعلق بالخادم والمتصفح ، لم يحدث أي إعادة توجيه - لقد تلقى للتو بعض كود HTML.

أداء أ Response.Redirect سوف تتسبب في تقديم طلب جديد إلى الصفحة الجديدة ، كما لاحظت ، في تقديم طلب جديد إلى الصفحة الجديدة ، مما يوضح للمستخدم العنوان الجديد في شريط العنوان. يتم استخدامه عادةً عندما تغير صفحة ما عنوانها فعليًا ، لكن المالكين ما زالوا يريدون الوصول إليه من عنوان URL الأصلي أيضًا.

تعديل: عينة إعادة توجيه إطار HTML: http://en.wikipedia.org/wiki/url_redirection#frame_redirects

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top