我有一個需要私有化的blogengine.net安裝。Privatizing BlogEngine.Net安裝
我正在做研究工作,但我必須保持我的博客/雜誌私人,直到某些條件得到滿足。
如何將我的blogEngine.net安裝進行私有化,以便讀者必須登錄才能閱讀我的帖子?
我有一個需要私有化的blogengine.net安裝。Privatizing BlogEngine.Net安裝
我正在做研究工作,但我必須保持我的博客/雜誌私人,直到某些條件得到滿足。
如何將我的blogEngine.net安裝進行私有化,以便讀者必須登錄才能閱讀我的帖子?
我使用這個擴展。只需將該文件保存爲您的App_Code \ Extensions文件夾中的RequireLogin.cs文件,並確保該擴展名已激活。
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BlogEngine.Core;
using BlogEngine.Core.Web.Controls;
using System.Collections.Generic;
/// <summary>
/// Summary description for PostSecurity
/// </summary>
[Extension("Checks to see if a user can see this blog post.",
"1.0", "<a href=\"http://www.lavablast.com\">LavaBlast.com</a>")]
public class RequireLogin
{
static protected ExtensionSettings settings = null;
public RequireLogin()
{
Post.Serving += new EventHandler<ServingEventArgs>(Post_Serving);
ExtensionSettings s = new ExtensionSettings("RequireLogin");
// describe specific rules for entering parameters
s.Help = "Checks to see if the user has any of those roles before displaying the post. ";
s.Help += "You can associate a role with a specific category. ";
s.Help += "All posts having this category will require that the user have the role. ";
s.Help += "A parameter with only a role without a category will enable to filter all posts to this role. ";
ExtensionManager.ImportSettings(s);
settings = ExtensionManager.GetSettings("PostSecurity");
}
protected void Post_Serving(object sender, ServingEventArgs e)
{
MembershipUser user = Membership.GetUser();
if(HttpContext.Current.Request.RawUrl.Contains("syndication.axd"))
{
return;
}
if (user == null)
{
HttpContext.Current.Response.Redirect("~/Login.aspx");
}
}
}
我認爲這是可能通過執行類似下面這樣做的網絡配置文件:
<system.web>
<authorization>
<allow roles="Admin" />
<deny users="*" />
</authorization>
</system.web>
lomaxx的答案沒有工作,所以我決定避免blogengine.net進行身份驗證的讀者。
在iis上,我禁用了匿名訪問並將訪客用戶添加到win2k3用戶列表中。
我們創建了一個簡單的工具,根據用戶的ASP.NET成員角色,某些用戶可以訪問某些帖子,以獲得相似的結果。
http://blog.lavablast.com/post/2008/08/BlogEnginenet-Post-Security.aspx
來源:BlogEngine.NET 2.5 - Private Blogs
如果你進入控制面板,用戶選項卡,角色子選項卡(右側),爲「無名氏」在右側工具區域,懸停在和選擇「權利」。
您現在處於Anonymous角色的Rights頁面。取消選中所有內容,特別是「查看公共帖子」。但是,您確實需要至少保留一個項目,否則一切都會恢復爲默認值。例如,您可以保留「查看對帖子的評分」。然後保存。
然後,任何未登錄的人都應該自動將其重定向到登錄頁面,而不管他們嘗試在哪個頁面進入該網站。
正是我所需要的,謝謝。 – Andy 2013-04-26 07:45:07
謝謝你的答案,但這並沒有工作:( 請參閱http://www.codeplex.com/blogengine/Thread/View.aspx?ThreadId=33705 – CVertex 2008-09-08 06:52:05