跳到主内容
深入学习SharePoint,MOSS,WSS,Silverlight

SharePoint学习

搜索
主页
解决方案
QFD 软件
SharePoint租用
SharePoint学习
SharePoint 2010
会员中心
客服中心
关于我们
留言
  

楠木科技 > SharePoint学习
深入学习 SharePoint,MOSS,WSS,Silverlight

 文档列表

展开/折叠 类别.NET WinForm ‎(9)
展开/折叠 类别ASP.NET ‎(17)
展开/折叠 类别ASP.NET MVC ‎(2)
展开/折叠 类别QFD 品质管理 ‎(3)
展开/折叠 类别SharePoint 管理 ‎(15)
展开/折叠 类别SharePoint 开发 ‎(43)
展开/折叠 类别SilverLight ‎(13)
展开/折叠 类别工作流-Workflow ‎(1)
展开/折叠 类别数据库 ‎(5)
展开/折叠 类别无题 ‎(8)

 最新文章

asp.net FormsAuthentication表单认证时如何弹出Windows登录窗口

asp.net 表单认证模式下,如何能够使用 浏览器 的登录窗口进行登录(IE使用Windows内置的验证窗口,Firefox、Chorme会弹出自带的小窗口进行登录)。

首先,修改Web.Config文件,设置为表单登录方式

<authentication mode="Forms">

  <forms loginUrl="~/Account/Login" defaultUrl="~/">

    <credentials passwordFormat="SHA1">

      <user name="admin" password="e9fe51f94eadabf54dbf2fbbd57188b9abee436e" />

    </credentials>

  </forms>

</authentication>

 

接下来,我们需要告诉浏览器,让其弹出登录小窗口,代码如下:

// Force the browser to pop up the login prompt

        Response.StatusCode = 401;

        Response.AppendHeader("WWW-Authenticate", "Basic");

        TempData["allowLogin"] = true;

 

我们已ASP.NET MVC来讲看一下完成代码;

下面是登录相关的Controller示例代码:

public class AccountController : Controller

{

    public void Login()

    {

        // Ensure there's a return URL

        if (Request.QueryString["ReturnUrl"] == null)

            Response.Redirect(FormsAuthentication.LoginUrl + "?ReturnUrl=" + Server.UrlEncode(FormsAuthentication.DefaultUrl));

 

        if (TempData.ContainsKey("allowLogin"))

        {

            // See if they've supplied credentials

            string authHeader = Request.Headers["Authorization"];

            if ((authHeader != null) && (authHeader.StartsWith("Basic")))

            {

                // Parse username and password out of the HTTP headers

                authHeader = authHeader.Substring("Basic".Length).Trim();

                byte[] authHeaderBytes = Convert.FromBase64String(authHeader);

                authHeader = Encoding.UTF7.GetString(authHeaderBytes);

                string userName = authHeader.Split(':')[0];

                string password = authHeader.Split(':')[1];

 

                // Validate login attempt

                if (FormsAuthentication.Authenticate(userName, password))

                {

                    FormsAuthentication.RedirectFromLoginPage(userName, false);

                    return;

                }

            }

        }

 

        // Force the browser to pop up the login prompt

        Response.StatusCode = 401;

        Response.AppendHeader("WWW-Authenticate", "Basic");

        TempData["allowLogin"] = true;

 

        // This gets shown if they click "Cancel" to the login prompt

        Response.Write("You must log in to access this URL.");

    }

}

asp.net Forms Authentication [FormsAuthentication] 详解

ASP.NET 使用 IIS作为Host,支持Windows认证和Forms(表单)认证,接下来让我们了解一下Forms认证的原理。

默认情况下,Asp.Net的Forms验证把验证票的据存储到Cookie,你可能会问这样Cookie不怕被看到吗? 

是的,Cookie会被看到,但是内容是加密的,即使看到也无法知道内容是什么。

 也有使用Session的方式来保存用户登录信息的,但是 Session方式是将验证信息存储在内存中,如果你使用的虚拟主机给你分配很小的内存,实际上都是如此,那么session就会很快过期,要求你重新登录,如果用户正在填写信息,被要求重新登录,那愤怒的感觉可想而知。

   cookie是存储在用户的客户端的。但是也会碰到失效的问题,下面一一来了解。
    在ASP.NET Forms验证中,通常我们会使用ASP.NET自带的Login控件来进行验证。同时,在web.config文件中,我们所有的Forms设置都设为默认。现在,问题就来了。
1.为什么我明明点了"Remember me",而大概半个小时后,我又Log out了?
2.为什么我明明设置了timeout为无限期 e.g. 400000,为什么一两天之后我又Log out了呢?
这是Forms验证中遇到的比较多的问题。下面,我就这两个问题做一个详细的解释:对于问题一,首先我要阐明ticket和cookie的区别。 cookie是一个容器,用来存放东西,它是保存在客户端的。而ticket是具体的数据,用来表示具体的验证信息,它是放在cookie这个容器中的。 因而,在我们验证的过程中,以下事情发生了。首先,ticket被创造了,里面包含着用户名等信息,同时它有一个过期时间。
    然后,cookie被创造了,它同样也有一个过期时间。最后,将ticket保存在cookie中,并将此cookie发送到client的浏览器中。读 到这里,我想问题已经很明白了,用户的Log out就是因为时间过期的问题。但具体是谁的时间过期了呢?在我们ASP.NET web.config的设置中,timeout是cookie的过期时间(注意,默认是30分钟),而ticket的过期时间是无限的,因为我们选 了"Remember me".这就是为什么虽然我点了"Remember me"。
    但在30分钟左右后,我仍然被Log out了,因为我们并没有设置cookie的timeout.ticket和cookie,只要其中之一不是永远不过期,我们都无法实现永不过期。  
    当我们解决了问题一后(假如手动设置timeout="4000000"),我们又遇到了问题二。这又是什么原因呢?这得从ticket的加密解密机制说 起。ASP.NET会使用一个machinekey来对cookie进行加密,这个machinekey默认是在application启动时随机生成 的。然后,ASP.NET会使用同一个machinekey进行cookie进行解密。正式因为这个key是application启动时随机生成的才导 致了问题二。试想,如果application recycle(重启)了怎么办?
ASP.NET会生成另一个key进行解密,以前的cookie将不再有效,这就是问题二的原因了。知道了这个,解决第二个问题的办法就很简单了, 手动设置一个特定的key.如:<machineKey validationKey="88CB6CA6CF403C5FBB41C2F62BB7FCFCA05DE7BE" decryptionKey="B8A7CF3816C57176" validation="SHA1" />
实现Asp.net Forms身份验证的操作步骤 
对于应用程序的身份验证,一直是自已编写登陆窗体,在窗体的CS文件中判断用户的登录 是否合法,如果合法则将用户名保存在Cookie中。然后将所有页面的继承于一个类似BaseForm这样的基页面,在这个页面的Page_Load事件 中加入判断,根据Cookie来判断用户是否已登录,如果没有登录则跳转到登录页面。最近作一个互连网网站,想起安全性的问题,查阅了一些资料后觉得采用Asp.net提供的标准的Forms验证方式。研究了一下,现在写出操作步骤,以供以后使用的时候参考(博客现在的一个很重要的功能就是用来保存曾经的学习积累)1、 修改web.config文件。如果vs2005的话,默认没有这个文件,调试时才会提示你是否要添加该文件。在web.config文件的<system.web>节中添加下面的三部分内容:<authentication mode="Forms">       <forms loginUrl="default.aspx" name=".ASPXFORMSAUTH">       </forms>     </authentication>     <authorization>       <deny users="?" />     </authorization>    <machineKey    validationKey="AutoGenerate,IsolateApps"    decryptionKey="AutoGenerate,IsolateApps"        validation="SHA1"    decryption="Auto" />上面三部分分别标有不同颜色,第一部分是设定应用程序的身份验证模式,默认是 windows,如果你的系统是在局域网内使用,并且整个局域网是工作在域模式下,那windows身份验证方式将会有很好的效果,如果多个B/S用 windows模式来进行身份验证,那么他们甚至可以非常方便的就实现了单点登陆的效果。但Forms身份验证使用的更普遍些,虽然相对来说他存在安全性 差的问题。在authentication节下有个forms节,在那里你可以填上执行你身份验证的页面,以及存储身份验证所采用的Cookie名称。如 果你不填写Cookie名称的话,Asp.net默认分配.ASPXFORMSAUTH作为Cookie名称。     第二部分authorization 是授权部分。你可以配置允许或拒绝某些用户或者角色来访问你的应用程序,他下面有deny,allow可以使用,搭配通配符?、*让我们可以非常轻易的配置出轻量级简单的身份验证体系。详细的配置信息可以参照asp.net的帮助文档,在此不在详细描述。     第三部分 machineKey 是用来配置存取Cookie时采用的加密/解密算法。有了这个算法后,Cookie应该算是比较安全了吧。2、 将Cookie信息登录后保存起来。FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket (1,CookieInfo , DateTime .Now, DateTime .Now.AddHours(20),false ,UserData ); // User data        string encryptedTicket = FormsAuthentication .Encrypt(authTicket); // 加密        //    存入Cookie        HttpCookie authCookie = new HttpCookie (FormsAuthentication .FormsCookieName,encryptedTicket);         authCookie.Expires = authTicket.Expiration;         Response.Cookies.Add(authCookie);首先创建一个身份票据,身份票据主要保存用户的名称,Cookie的过期时间,另外你还 可以保存一些额外数据,比如用户所扮演的角色。这里有个地方要注意,UserData是用来保存一些额外数据,比如角色,但如果我没有数据的话,通常会传 一个null值进去,但如果你是想将Cookie信息进行加密保存的话,这里不能传null值,你可以传一个””值。如果传null值的话,在执行string encryptedTicket = FormsAuthentication .Encrypt(authTicket); 的时候会返回一个null值,以至于生成一个错误的加密Cookie值。如果要将Cookie进行长期保存,需要为Cookie设置一个过期时间。3、 读取保存在计算机中的Cookie。在Global.asax 文件中存在Application_AuthenticateRequest事件,它是执行所有服务器端请求的时候执行。因此我们可以在这个地方读取Cookie并进行解密。以下是示例代码:protected void Application_AuthenticateRequest(object sender, EventArgs e)     {        string cookieName = FormsAuthentication .FormsCookieName;// 从验证票据获取Cookie的名字。        // 取得Cookie.        HttpCookie authCookie = Context.Request.Cookies[cookieName];        if (null == authCookie)            return ;        FormsAuthenticationTicket authTicket = null ;        // 获取验证票据。         authTicket = FormsAuthentication .Decrypt(authCookie.Value);        if (null == authTicket)            return ;               // 验证票据的UserData中存放的是用户角色信息。        //UserData 本来存放用户自定义信息。此处用来存放用户角色。        string [] roles = authTicket.UserData.Split(new char [] { ',' });        FormsIdentity id = new FormsIdentity (authTicket);        GenericPrincipal principal = new GenericPrincipal (id, roles);        // 把生成的验证票信息和角色信息赋给当前用户.         Context.User = principal;     }当你对Cookie加密存储之后必须要进行解密后才能进行使用。4、 在每个页面读取Cookie的值。可以通过下面的语句来读取Cookie的值。HttpContext .Current.User.Identity.Name


在项目中用到的验证(并没有实现cookis不过期):  public class  LoginUserManager : ILoginUserManager    {        private IUserService userService;
        public IUserService UserService        {            set { userService = value; }        }
        public void MarkCurrentUser(User user, bool isPersistent)        {            string mUserData = string.Format("{0};{1};{2}", user.Account, user.UserName, user.EmployeeNO);            SaveToCookies(user.Account, mUserData, isPersistent);        }
        public User CurrentUser(bool fullData)        {            User member = GetFromCookies<User>();            if (fullData && member != null && !string.IsNullOrEmpty(member.Account))            {                return userService.GetObjectById(null, member.Account);            }            return member;        }
        private static T GetFromCookies<T>() where T : class        {            if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated            && (HttpContext.Current.User.Identity is FormsIdentity))            {                HttpCookie myCookie = HttpContext.Current.Request.Cookies["ud"];                if (myCookie != null && !string.IsNullOrEmpty(myCookie.Value))                {                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(myCookie.Value);                    if (ticket != null)                    {                        string[] userInfoArray = ticket.UserData.Split(';');                        //UserData format like as "loginName;password;role1,role2,role3..."                        if (userInfoArray.Length == 3 && typeof(T).Name == "User")                        {                            User member = new User();                            member.Account = userInfoArray[0];                            member.UserName = userInfoArray[1];                            member.EmployeeNO = userInfoArray[2];                            return member as T;                        }                    }                }            }            return default(T);        }
        private static void SaveToCookies(string name, string mUserData, bool isPersistent)        {            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(                1,                name,                DateTime.Now,                DateTime.Now.AddDays(1),                isPersistent,                mUserData);            string hashTicket = FormsAuthentication.Encrypt(ticket);            HttpCookie cookie = new HttpCookie("ud", hashTicket);            if (HttpContext.Current.Response.Cookies["ud"] != null)            {                HttpContext.Current.Response.Cookies["ud"].Expires = DateTime.Now.AddDays(-1d);            }            HttpContext.Current.Response.Cookies.Add(cookie);        }    }

Silverlight How To Refresh Other Project’s Clientbin

Silverlight ClientBin and test page project and deployment

1. is there any way to recover my client bin on my TestProject? Because the .xap that i generated after i deleted the ClientBin does not refresh at all.

-> You can go to Web Site project – > Right click and goto properties – > Find Silverlight section. Then remove the existing silverlight project. Then click on Add button. It will allow you to choose the folder you like to keep the .XAP file.

2. How to create another TestProject if i deleted the whole TestProject(that i created while i started my Silverlight 2.0 project)?

-> Right click to the solution and Add new project. You can choose the existing web application where it will add the .XAP file or your can latter attach the Silverlight project to web site using above procedure.

3. Which xap that we have to copy to our production server? is it the one in ClientBin(from TestProject) or is it the one in Bin(from the Project where the app.xaml and page.xaml exist)?

-> I think if your configuration folder is right then take it from ClientBin or you can even take it from Bin folder.

4. What are the files that we need to copy to production server besides .xap?

-> The test pages (.html / .aspx). If any images/videos from Web applications folder. The utilized resources.

5. Is the files in the .xap already include all the medias that we used, for example images , video etc?

-> If you would like to embedd these resources in side .XAP file, then right click to each Image/Video then goto property bag. Change Build Action Property to “Content“. Copy to output Directory property to “Copy if Newer“. Now when accessing these resources from Silverlight you will have to make a small change. You will have to use “/” forward slash to fetch these resources.

SharePoint 工作流开发 - 20110417

其实,SharePoint工作流的开发没有想象中的麻烦,它可以很容易的实现出复杂的工作流,可以复杂到填写N个表单、N次审批、触发多个子流程等。

  • 工作流状态,SPWorkflowState,  数据类型为Int型,0-15为系统保留的状态,我们可以自定义工作流状态,在工作流Feature中,找到 MetaData 元素,添加ExtendedStatusColumnValues元素,并在其中添加StatusColumnValue子元素,如:<ExtendedStatusColumnValues><StatusColumnValue>1. Shell</StatusColumnValue> <StatusColumnValue>2. Draft</StatusColumnValue> <StatusColumnValue>3. In Review</StatusColumnValue> <StatusColumnValue>4. Submitted</StatusColumnValue> <StatusColumnValue>5. Final</StatusColumnValue></ExtendedStatusColumnValues>,这个时候就可以使用SetState活动来设置流程的状态;
  • 更新工作流任务的方法:SPWorkflowTask.AlertTask,有时候你会发现通过代码来修改工作流任务时,不能触发流程的运行,其实,SharePoint提供了修改工作流任务的方法,来及时的触发流程继续执行,这个方法就是SPWorkflowTask.AlertTask方法,如:SPSite site = new SPSite(http://henry/);SPWeb web = site.OpenWeb);SPList doclib = web.Lists["合同管理"];SPListItem doc = oclib.Items[0];SPWorkflowTaskCollection tasks = doc.Workflowsdoc.Workflows.Count-1].Tasks; //找具体SPWorkflowTaskHashtable ht = new Hashtable();ht.AddSPBuiltInFieldId.Completed, true); //任务设置完成状态ht.AddSPBuiltInFieldId.TaskStatus, "已完成");//任务任务列表显示状态设置“已完”ht.Add(SPBuiltInFieldId.PercentComplete, 1); //任务任务列表完成百分比设“100%”ht.Add(SPBuiltInFieldId.WorkflowOutcome, "Some output nfomation"); //设置任务输出消息,等同于使Visual Studio设计工作流时,ompleteWorkflow活动TaskOutput属性SPWorkflowTask.AlterTask(tasks[0], t, rue);

今天先说这么多,后面会继续

Reship:在TFS 2010中使用邮件提醒功能(Email Notification)
  • 1.安装SMTP Server

首先,在装有TFS 2010的服务中先安装SMTP服务,我使用的是Windows Server 2008,在Server Manager中安装SMTP功能,如下图:

 

 

  • 2.IIS6中配置SMTP Server

要想让TFS的邮件提醒功能将邮件转发到第三方邮箱(如@live.cn@163.com等),需要进行邮件转发设置,打开IIS6,如下图:

 

 

SMTP Virtual Server属性中,

1)设置IP地址:

2)设置Relay Restrictions

  • 3.IIS7中配置SMTP Server

需要为SMTP Server分配一个E-mail地址。打开IIS7,设置Email地址以及转到本地SMTP服务器,如下图:

  • 4.配置TFS 2010

Team Foundation Server Administration Console中,设置邮件提醒参数,如下图:

  • 5.客户端设置

Visual Studio 2010的菜单栏找到邮件邮件提醒设置:Team –> Project Alerts(只有已连接到TFS服务器后才有此选项),输入需要提醒的事件以及接收提醒的邮箱,如下图:

到此,Project Alerts邮件提醒功能设置 完毕,现在看看效果如何。Check in 一个文件后,应该会收到一封邮件。

1 - 5 下一步

 SharePoint & MOSS 资源

 ‭(隐藏)‬ 管理链接

 SharePoint & MOSS

  SharePoint 团队
  SharePoint交流
  SharePoint 2010

 文章分类

 常用链接

©2007 - 2012 SharePoint