- In XCode project General tab, make necessary updates to Version and Build number
- Set Build Only Device to Generic iOS Device
- Run Product>Archive
- Upon successful build and archive, click 'Upload to App Store' button
- Chose proper team for the submission
- Click 'Upload' to send the app to Apple
- Wait... until you get upload completed confirmation.
Friday, March 4, 2016
Steps to upload iOS app to Apple Store
Tuesday, February 23, 2016
Git commands: get older version, set user email
From time to time there may be a need to play with a snapshot of an early version of code. Some Git/GitHub UI tool can help to do this, but it also just takes a few lines of command to do so. I use Mac as an example:
Check out older snapshot:
- Find the last commit you want to go back to. Copy the commit Id. It usually looks like this: 9d4f59ecf2eef3b8a46c5ba4a47a4efc27bf57b4
- Open Terminal, change to the directory where you code base were checked out.
- Enter: git checkout {Commit Id}
- You may see message like this:
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.
Return to latest version of master branch:
- Enter: git checkout master
Setup user email for local Git repository:
- Enter: git config --global user.email "{user email}"
To verify user email:
- Enter: git config --global user.email
Check out older snapshot:
- Find the last commit you want to go back to. Copy the commit Id. It usually looks like this: 9d4f59ecf2eef3b8a46c5ba4a47a4efc27bf57b4
- Open Terminal, change to the directory where you code base were checked out.
- Enter: git checkout {Commit Id}
- You may see message like this:
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.
Return to latest version of master branch:
- Enter: git checkout master
Setup user email for local Git repository:
- Enter: git config --global user.email "{user email}"
To verify user email:
- Enter: git config --global user.email
Monday, February 23, 2015
How to generate report with data from different databases
From time to time we need to generate reports referencing
data from other database. In SSRS, One simple way is to utilize its Lookup function.
All you need to do is create multiple datasets pointing to different
databases (data sources). Then use Lookup function following this syntax:
Lookup (src_expression,
target_expression, target_result_expression, target_dataset)
For example, you have application user dataset, say AppUsers(Uid)
and membership dataset, say MembershipUsers(Mid, Name). To lookup application
user name from membership, the expression will be something like this:
Lookup(Field!Uid.Value,
Field!Mid.Value, Field!Name, “MembershipUsers”)
Notice, Lookup function is good for 1-to-1 source/target field
value match. To handle 1-to-many matches, use LookupSet instead.
Tuesday, November 4, 2014
Simple way to compress Web API Response
There are many ways to do Web API Response compression. I particularly like Radenko Zec's solution mostly because it's simple and efficient.
A few steps I did in my project:
- Pick your favorite compression tool. I used DotNetZip as Radenko recommended. It gives me close to 85% compression rate for JSON. A CompressionHelper is used as well so that I can easily change to a different compression tool if I want.
- Implement DeflateCompressionAttribute. Mostly Radenko's code:
{
public override void OnActionExecuted(HttpActionExecutedContext actContext)
{
var content = actContext.Response.Content;
var bytes = content == null ? null : content.ReadAsByteArrayAsync().Result;
var compressedContent = bytes == null ? new byte[0] : CompressionHelper.Compress(bytes);
actContext.Response.Content = new ByteArrayContent(compressedContent);
actContext.Response.Content.Headers.Remove("Content-Type");
actContext.Response.Content.Headers.Add("Content-encoding", "deflate");
actContext.Response.Content.Headers.Add("Content-Type", "application/json");
base.OnActionExecuted(actContext);
}
}
- Add [DeflateCompression] attribute to any WebAPI method needs compression
- Decompress using standard HttpClientHandler. As our Web API client is expecting objects, we configure HttpClientHandler to decompress response:
using (var client = new HttpClient(new HttpClientHandler(){AutomaticDecompression = DecompressionMethods.Deflate|DecompressionMethods.GZip}))
{
var para = new ServiceParams();
client.BaseAddress = new Uri(_serviceUrl);
client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
HttpResponseMessage response =
client.PostAsync(_servicePath, para, new JsonMediaTypeFormatter()).Result;
r = response.Content.ReadAsAsync<ServiceResponse>().Result;
}
Monday, September 10, 2012
Give the Badmail messages a second chance
You don't do this everyday, so just post it here for the record.
Steps to resend bad messages:
- Stop the SMTP Service: Open IIS Manager, right-click SMTP Virtual Server, then click Stop.
- Copy all bad message files (with extension of .bad) under Badmail folder to Pickup folder
- Remove the .bad extension
- Start the SMTP service, and watch them being redelivered.
File types under Badmail folder:
- .bad: the message failed to send
- .bdp: the diagnostic message
- .bdr: the body of the (None-delivery report) NDR.
Steps to resend bad messages:
- Stop the SMTP Service: Open IIS Manager, right-click SMTP Virtual Server, then click Stop.
- Copy all bad message files (with extension of .bad) under Badmail folder to Pickup folder
- Remove the .bad extension
- Start the SMTP service, and watch them being redelivered.
File types under Badmail folder:
- .bad: the message failed to send
- .bdp: the diagnostic message
- .bdr: the body of the (None-delivery report) NDR.
Tuesday, July 10, 2012
Claim-Based Authorization for ASP.NET MVC
As WIF becoming an official part of .NET 4.5, more attentions have been paid to integrate it with other .NET technologies, like MVC or Azure. Many consider WIF as a Claim-based authentication standard, actually it also comes with a well-rounded Claim-based user authorization mechanism. In this post, I'll discuss the following topics to show how easy to apply Claim-based authentication to ASP.NET MVC, and how powerfully and flexible it can be compare to standard Role-based authentication:
WIF provides a claims authorization manager for 'an extensibility point from which you can authorize access to a resource based on the claims presented in a token, before your RP application is called (from msdn)'. I personally like it because the following reasons:
To use custom authorization manager, just define it in claimsAuthorizationManager section in web.config. Something like this:
Please note, configuring claim authorization manager policies is another way to define your access control logic. It's good to use in a way that it requires less code changes when access logic changed. But it's relatively rigid, so not my favorite.
Apply to ASP.NET MVC
Now you can apply ClaimsPrincipalPermission attribute to any Controller Actions you plan to do access control. Just make sure to provide correct resource(s) and operation as parameters, because they will be used by claim authorization manager to make access control decision.
Similar authorization control can also be used for AJAX Web Services. In this case, simply apply ClaimsPrincipalPermission Attribute to Web Method. Make sure AJAX client to handle the security exception once an access attempt is denied.
- Claims Authorization Manager
- Apply to ASP.NET MVC
WIF provides a claims authorization manager for 'an extensibility point from which you can authorize access to a resource based on the claims presented in a token, before your RP application is called (from msdn)'. I personally like it because the following reasons:
- It makes more factors available for consideration as to doing access control logic, like Resources, Operations, Principle Claims(including Roles), all of which enable more detailed access control than regular Role-based access control.
- When used with .NET Attributes, it provides a clean separation between the code to implement a feature and the code to implement access control. See sample code below.
public class MyClaimAuthorizationManager : ClaimsAuthorizationManager
{
public override bool CheckAccess(AuthorizationContext context)
{
var claimsId = context.Principal.Identity as IClaimsIdentity;
if(claimsId==null || !claimsId.IsAuthenticated)
{
return false;
}
var resource = context.Resource.First().Value;
var operation = context.Action.First().Value;
{
public override bool CheckAccess(AuthorizationContext context)
{
var claimsId = context.Principal.Identity as IClaimsIdentity;
if(claimsId==null || !claimsId.IsAuthenticated)
{
return false;
}
var resource = context.Resource.First().Value;
var operation = context.Action.First().Value;
// Do your access control logic here
// ...
return false;
}
}
To use custom authorization manager, just define it in claimsAuthorizationManager section in web.config. Something like this:
<microsoft.identityModel>
<service>
<claimsAuthorizationManager type="MyNameSpace.MyClaimAuthorizationManager">
<service>
<claimsAuthorizationManager type="MyNameSpace.MyClaimAuthorizationManager">
<policy resource="http://localhost/MyService.svc" action="GET">
<claim claimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dateofbirth" minAge="21" />
</policy>
<claim claimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dateofbirth" minAge="21" />
</policy>
</claimsAuthorizationManager>
...
</service>
</service>
</ microsoft.identityModel>
Please note, configuring claim authorization manager policies is another way to define your access control logic. It's good to use in a way that it requires less code changes when access logic changed. But it's relatively rigid, so not my favorite.
Apply to ASP.NET MVC
Two things need to be handled before you can fully enjoy the claim-based access control for MVC. First, make sure your controller responsive to System.Security.SecurityException. This can be achieved by applying HandleError Attribute to controller, so MVC knows which view to go in the case of an access attempt is denied. Of course, the same attribute can be applied at Controller Action level for more fine-grained access-deny handling. Secondly, make sure your application supports custom Error handling. This can be achieved by setting customError mode to ‘On’ in
web.config.
<system.web>
<customErrors
mode="On"
defaultRedirect="Home/Logout"></customErrors>
…
</system.web>
Now you can apply ClaimsPrincipalPermission attribute to any Controller Actions you plan to do access control. Just make sure to provide correct resource(s) and operation as parameters, because they will be used by claim authorization manager to make access control decision.
[HandleError(ExceptionType = typeof(SecurityException), View = "Home/Login")]
public class MyController : Controller
{
[ClaimsPrincipalPermission(SecurityAction.Demand, Resource = MyResources.REPORTS_ACCESS, Operation = MyOperations.GET)]
public ActionResult ViewReport()
{
public class MyController : Controller
{
[ClaimsPrincipalPermission(SecurityAction.Demand, Resource = MyResources.REPORTS_ACCESS, Operation = MyOperations.GET)]
public ActionResult ViewReport()
{
...
return View();
}
...
}
return View();
}
...
}
Similar authorization control can also be used for AJAX Web Services. In this case, simply apply ClaimsPrincipalPermission Attribute to Web Method. Make sure AJAX client to handle the security exception once an access attempt is denied.
Labels:
.Net,
Authorization,
C#,
Claim-based,
MVC,
WIF
Sunday, March 11, 2012
God Mode for Windows 7
Windows 7 has a hidden feature called 'God Mode'. It actually a simple folder which contains links for most of the windows settings. So where is it then? The answer may surprise you: anywhere. Simply create a new folder from any place you want, and name it as:
GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
That's it! Enjoy:)
GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
That's it! Enjoy:)
Subscribe to:
Posts (Atom)